<?php


namespace app\index\controller;
use app\common\logic\UserLogic;
use think\Controller;

class Shares extends Base
{
    //传递加密id
    public function qrcode()
    {
        $us_id = $this->user['id'];
        $us_type = model('User')->where('id',$us_id)->value('us_type');
        if ($us_type == 1)
        {
            $this->e_msg('该用户为会员，不能分享');
        }else{
            $code = encrypt($us_id);
            $this->s_msg('',$code);
        }

    }

    // 扫描二维码，通过 id 获取推荐人手机号
    public function getTelById(){
        $id = input('post.us_id');
        $id = decrypt($id);
        $p_tel = model('User')->where('id',$id)->value('us_tel');
        $this->s_msg(null,$p_tel);
    }

    // 注册
    public function register()
    {
        $data = input('post.');
        $code_info = cache($data['us_tel'] . 'code') ?: "";
        if (!$code_info) {
            $this->e_msg('请重新发送验证码');
        } elseif (trim(input('post.code')) != $code_info) {
            $this->e_msg('验证码不正确');
        }
        unset($data['code']);
        $addUser = new UserLogic;
        //添加用户
        $rel = $addUser->addUser($data);
        if ($rel['code'] == 0) {
            $this->e_msg($rel['msg']);
        }
        $this->s_msg(null, $rel['msg']);
    }

}